package com.eascs.workflow.massSms.dao.impl;


import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.site.cookie.CookieSpec;
import com.eascs.web.context.RequestContext;
import com.eascs.web.interceptor.ActionInterceptor;
import com.eascs.workflow.common.dao.BaseDao;
import com.eascs.workflow.common.entity.sys.WfMessage;
import com.eascs.workflow.massSms.dao.IMassSmsDao;
import com.eascs.workflow.massSms.vo.MassSmsVo;


@Repository
public class MassSmsDaoImpl extends BaseDao implements IMassSmsDao {

	@Override
	public PageResult<Object[]> getSmsList(MassSmsVo vo) {
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, vo.getPageSize(), vo.getPageIndex());

		StringBuffer querySqlBuf = new StringBuffer("select t.request_id, t.biz_code,t.receive_telphone,t.send_type,t.creator,t.create_time,t.`status` from wf_message t where 1=1 ");
		querySqlBuf.append("and t.system_code='群发短信'");
		if (StringUtils.isNotBlank(vo.getBizCode())) {
			querySqlBuf.append(" AND t.biz_code  = ?");
			sqlPageQuery.addParam(vo.getBizCode());
		}
		if (StringUtils.isNotBlank(vo.getRemark())) {
			querySqlBuf.append(" AND t.remark like ?");
			sqlPageQuery.addLikeParam(vo.getRemark());
		}
		if (StringUtils.isNotBlank(vo.getStatus())) {
			querySqlBuf.append(" AND t.status = ?");
			sqlPageQuery.addParam(vo.getStatus());
		}
		if (StringUtils.isNotBlank(vo.getSendType())) {
			querySqlBuf.append(" AND t.send_type = ?");
			sqlPageQuery.addParam(vo.getSendType());
		}
		if (StringUtils.isNotBlank(vo.getContent())) {
			querySqlBuf.append(" AND t.content = ?");
			sqlPageQuery.addLikeParam(vo.getContent());
		}
		if (StringUtils.isNotBlank(vo.getCreator())) {
			querySqlBuf.append(" AND t.creator = ?");
			sqlPageQuery.addParam(vo.getCreator());
		}
		if (StringUtils.isNotBlank(vo.getBeginDate())) {
			querySqlBuf.append(" AND t.create_time > ?");
			sqlPageQuery.addParam(vo.getBeginDate());
		}
		if (StringUtils.isNotBlank(vo.getEndDate())) {
			querySqlBuf.append(" AND t.create_time < ?");
			sqlPageQuery.addParam(vo.getEndDate());
		}
		querySqlBuf.append(" order by  t.create_time  desc ");
		sqlPageQuery.setQuerySql(querySqlBuf.toString());
		return super.findDataWithPage(sqlPageQuery);
	}

	@Override
	public WfMessage findByrequestId(String requestId) {
		String sql = "SELECT * from wf_message  WHERE request_id = ?";
		return super.findEntity(sql, WfMessage.class, requestId);
	}
	
	
	
	
	@Override
	public WfMessage saveSms(WfMessage wf){
	 return	super.insert(wf);
	}
}
